package com.smart.manager.wiki.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.ArcoTips;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.wiki.entities.body.RIntelRemind;
import com.smart.manager.wiki.entities.models.WikiIntelRemind;
import com.smart.manager.wiki.entities.repository.IntelRemindRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * @author Administrator
 */

@Api(tags = "消息提醒")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "wiki/intel/remind")
@RequiredArgsConstructor
public class IntelRemindApi {

    private final IntelRemindRepository remindRepository;


    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询提醒")
    @SaCheckPermission("wiki:intel:remind:pageList")
    public AjaxResult<Page<WikiIntelRemind>> pageList(@Validated RIntelRemind.SearchBody body) {
        Page<WikiIntelRemind> result = remindRepository.pageList(body);
        return AjaxResult.data(result);
    }




    @PostMapping(value = "add")
    @ApiOperation(value = "新增提醒")
    @SaCheckPermission("wiki:intel:remind:add")
    public AjaxResult<String> add(@RequestBody @Validated RIntelRemind.EditBody body) {
        remindRepository.add(body);
        return AjaxResult.success();
    }


    @PutMapping(value = "update/{id}")
    @ApiOperation(value = "修改提醒")
    @SaCheckPermission("wiki:intel:remind:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RIntelRemind.EditBody body) {
        remindRepository.update(id, body);
        return AjaxResult.success();
    }


    @DeleteMapping(value = "delete")
    @ApiOperation(value = "删除提醒")
    @SaCheckPermission("wiki:intel:remind:delete")
    public AjaxResult<Integer> delete(@RequestBody @NotEmpty(message = ArcoTips.PK_EMPTY) List<Long> ids) {
        int x = remindRepository.delByIds(ids);
        return AjaxResult.delSuccess(x);
    }

}
